<?php
class MessageModule
{
	public function index()
	{
		global $_FANWE;
		
		$cache_args = array(
			$_FANWE['cookie']['city_py'],
		);
		
		$_FANWE['nav_title'] = lang('common','message_index');
		$cache_file = getTplCache('page/message_index',$cache_args);
		
		//用于留言的发表频率限制
		$key = $_FANWE['uid'].'_check_message_submit';
		if(empty($_FANWE['cookie'][$key]))
			fSetCookie($key, authcode($_FANWE['client_ip']."\t0", 'ENCODE'),604800, 1, true);
		
		if(!@include($cache_file))
			include template('page/message_index');
		
		display($cache_file);
	}
	
	public function submit()
	{
		global $_FANWE;
		$_FANWE['nav_title'] = lang('common','message_index');
		$data['user_email'] = $_FANWE['request']['user_email'];
		$data['user_name'] = $_FANWE['request']['user_name'];
		$data['title'] = $_FANWE['request']['title'];
		$data['content'] = $_FANWE['request']['content'];
		$data['qq_msn'] = $_FANWE['request']['qq_msn'];
		$data['tel'] = $_FANWE['request']['tel'];
		$data['user_email'] = $_FANWE['request']['user_email'];
		$data['rec_module'] = 'Feedback';
		$data['status'] = 0;
		$data['create_time'] = TIME_UTC;
		$data['update_time'] = TIME_UTC;
		
		$validate = array(
			array('user_name','required',lang('message','name_empty')),
			array('title','required',lang('message','title_empty')),
			array('content','required',lang('message','content_empty')),
		);
		
		$error = '';
		
		if(S('Validate')->validation($validate,$data))
		{
			if(!empty($data['user_email']) && !S('Validate')->email($data['user_email']))
				$error = lang('message','email_error');
			
			if(!empty($data['qq_msn']) && !S('Validate')->qqMsn($data['qq_msn']))
				$error = lang('message','qq_msn_error');
		}
		else
			$error = S('Validate')->getError();
		
		
		if($error == '')	
		{
			if(checkIpOperation("message_submit",$_FANWE['setting']["message_inteval"]))
			{
				if(DB::insert('message',$data))
				{
					showSuccess(lang('message','message_tooltip'),
								lang('message','message_success'),
								U('index/index'));
				}
				else
					$error = lang('message','message_error');
			}
			else
				$error = lang('message','message_frequent');
		}
		
		
		$message = &$data;
		include template('page/message_index');
		display();
	}
}
?>